package no.nordicsemi.android.nrfmesh.auth.ui.register;

import android.os.Bundle;
import android.view.*;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import no.nordicsemi.android.nrfmesh.R;
import no.nordicsemi.android.nrfmesh.auth.data.AuthRepository;
import no.nordicsemi.android.nrfmesh.auth.ui.AuthActivity;
import no.nordicsemi.android.nrfmesh.auth.ui.AuthViewModel;

/** 仅允许 USER / DOCTOR；开发者不在注册流程 */
public class RolePickFragment extends Fragment {
    private AuthViewModel vm;

    @Nullable @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_role_pick, container, false);
        vm = new ViewModelProvider(requireActivity()).get(AuthViewModel.class);

        Button btnUser = v.findViewById(R.id.btnUser);
        Button btnDoctor = v.findViewById(R.id.btnDoctor);

        btnUser.setOnClickListener(view -> {
            vm.role = AuthRepository.ROLE_USER;
            ((AuthActivity) requireActivity()).goTo(new RegCredentialsFragment(), true);
        });
        btnDoctor.setOnClickListener(view -> {
            vm.role = AuthRepository.ROLE_DOCTOR;
            ((AuthActivity) requireActivity()).goTo(new RegCredentialsFragment(), true);
        });
        return v;
    }
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // 追加这一行
        applyHeroPaneEnhancements(view);
    }
    /** 右栏卡片入场动效 + 文案可选中（与登录页一致） */
    private void applyHeroPaneEnhancements(@NonNull View root) {
        MotionLayout ml = root.findViewById(R.id.heroPane);
        if (ml != null) {
            ml.post(ml::transitionToEnd);
        }
        int[] textIds = { R.id.tvDeviceIntro, R.id.tvBullets, R.id.tvDisclaimer };
        for (int id : textIds) {
            View v = root.findViewById(id);
            if (v instanceof TextView) {
                ((TextView) v).setTextIsSelectable(true);
            }
        }
    }
}
